package com.wbao.dianniu.emojiUtils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;


import com.wbao.dianniu.R;

import java.util.List;

/**
 * Created by zejian
 * Time  16/1/7 下午4:46
 * Email shinezejian@163.com
 * Description:
 */
public class EmotionGridViewAdapter extends BaseAdapter {

    private Context context;
    private List<String> emotionNames;
    private int itemWidth;
//    private int emotion_map_type;

    public EmotionGridViewAdapter(Context context, List<String> emotionNames, int itemWidth, int emotion_map_type) {
        this.context = context;
        this.emotionNames = emotionNames;
        this.itemWidth = itemWidth;
//        this.emotion_map_type = emotion_map_type;
    }

    @Override
    public int getCount() {
        // +1 最后一个为删除按钮
        return emotionNames.size() + 1;
    }

    @Override
    public String getItem(int position) {
        return emotionNames.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler viewHodler = null;
        if (null == convertView) {
            viewHodler = new ViewHodler();
            convertView = LayoutInflater.from(context).inflate(R.layout.emoji_gridview_item, null);
            viewHodler.imageButton = convertView.findViewById(R.id.gridview_item_imageButton);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHodler) convertView.getTag();
        }

        //判断是否为最后一个item
        if (position == getCount() - 1) {
            viewHodler.imageButton.setBackgroundResource(R.drawable.ic_emojis_delete);
        } else {
            String emotionName = emotionNames.get(position);
            int drawbleId = EmotionUtils.emojiMap.get(emotionName);
            viewHodler.imageButton.setBackgroundResource(drawbleId);
        }

        return convertView;
    }

    class ViewHodler {
        public ImageView imageButton;
    }

}
